package com.qf.rabbitmqspringboot.dead;

import com.qf.rabbitmqspringboot.config.DeadLetterConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 死信队列消费者
 */
@Component
public class DeadListener {

    @RabbitListener(queues = DeadLetterConfig.DEAD_QUEUE)
    public void consume(String msg, Channel channel, Message message) throws IOException {
        System.out.println(System.currentTimeMillis() + ",接收到消息：" + msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

}
